make_mk_fnc = $(1)/$(notdir $(1)).mk
make_obj_fnc = $(BUILD_OBJ_PATH)/$(strip $(1)).o
make_dep_fnc = $(BUILD_OBJ_PATH)/$(strip $(1)).d

COMP_MK = $(call make_mk_fnc,$(COMP_PATH))
include $(COMP_MK)

OBJECTS := $(foreach n, $(addprefix $(COMP_PATH)/,$(strip $($(NAME)_SRCS))), $(call make_obj_fnc, $(n)))
DEPENDS := $(foreach n, $(addprefix $(COMP_PATH)/,$(strip $($(NAME)_SRCS))), $(call make_dep_fnc, $(n)))
ARCHIVE := $(BUILD_OBJ_PATH)/$(COMP_PATH)/lib$(notdir $(COMP_PATH)).a

$(ARCHIVE): $(OBJECTS)
	@echo ----- archiving $@
	@-rm -f $@
	$(Q)$(AR) -rc $@ $^

$(OBJECTS):$(BUILD_OBJ_PATH)/%.o:%
	@echo ----- compiling $<
	@mkdir -p $(BUILD_OBJ_PATH)/$(dir $<)
	$(Q)$(CC) -c $< $(foreach i, $(COMP_IFLAGS) $(IFLAGS), -I$(i)) $(foreach d, $(DFLAGS) $(COMP_DFLAGS), -D$(d)) $(CFLAGS) $($(NAME)_CFLAGS) -o $@ -MMD -MF $(BUILD_OBJ_PATH)/$<.d -MP || (rm -f $(ARCHIVE); exit 1)

$(foreach d, $(DEPENDS), $(eval -include $(d)))
